package com.yue.servlet;

import com.yue.util.FileLoadUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 功能描述: TODO <br/>
 * 创建时间: 2016/11/30<br/>
 *
 * @author QiuYang
 */
@WebServlet(name = "uploadServlet", urlPatterns = {"/upload"})
@MultipartConfig
public class UploadServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Part part = req.getPart("file");
        PrintWriter out = resp.getWriter();

        out.println("file size : " + part.getSize() + "<br/>");
        out.println("file type : " + part.getContentType() + "<br/>");
        out.println("file name : " + part.getName() + "<br/>");
        out.println(FileLoadUtil.getFileType(part));
        out.println(FileLoadUtil.getFileName(part));

        part.write("C:\\Users\\hg\\Desktop\\test\\file_upload_dir\\"+FileLoadUtil.getFileName(part));

    }
}
